package com.example.safelib.adapter

import android.graphics.Color
import android.widget.ImageView

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.example.baselib.utils.TimeUtils
import com.example.safelib.R
import com.example.safelib.bean.SafeAlarmBean


class SafeAlarmAdapter(layoutResId: Int) :
    BaseQuickAdapter<SafeAlarmBean, BaseViewHolder>(layoutResId) {

    override fun convert(helper: BaseViewHolder, item: SafeAlarmBean) {
        helper.getView<ImageView>(R.id.safe_alarm_sh).setImageResource(R.mipmap.expand)
        helper.setGone(R.id.safe_alarm_more_ly, false)
        helper.addOnClickListener(R.id.safe_alarm_clxx_rl)
        if (item.endtime == null) {
            helper.setTextColor(R.id.safe_alarm_etime,Color.parseColor("#FF0000"))
        }else helper.setTextColor(R.id.safe_alarm_etime,Color.parseColor("#222222"))
        var value: String = item.alarmvalue
        if (item.typename != null && item.typename == "开关量") {
            value = if (value == "0.00") item.offdescribe else item.ondescribe
        }
        helper.setText(
            R.id.safe_alarm_ser,
            (helper.position + 1).toString() + " " + "-" + " " + item.sensorname
        ).setText(R.id.safe_alarm_sno, item.sensornum)
            .setText(R.id.safe_alarm_stime, TimeUtils.timeFormat(item.starttime))
            .setText(R.id.safe_alarm_ltime, TimeUtils.secondToString(item.persisttime))
            .setText(R.id.safe_alarm_value, value + (item.sensorunit ?: ""))
            .setText(R.id.safe_alarm_stats, item.statusdec)
            .setText(R.id.safe_alarm_local, item.sensorplace)
            .setText(R.id.safe_alarm_station, item.stationnum)
            .setText(
                R.id.safe_alarm_etime,
                if (item.endtime == null) "正在报警" else TimeUtils.timeFormat(item.endtime)
            )
            .setText(R.id.safe_alarm_cltime, item.minedispose_time)
            .setText(R.id.safe_alarm_measure, item.minedispose)
            .setText(R.id.safe_alarm_clr, item.minedispose_person)
            .setText(R.id.safe_alarm_reason, item.alarmreason)

    }


}
